package com.ruoyi.shopping.service.impl;

import com.ruoyi.shopping.domain.CommodityReply;
import com.ruoyi.shopping.mapper.CommodityLikeEvaluateMapper;
import com.ruoyi.shopping.mapper.CommodityReplyMapper;
import com.ruoyi.shopping.service.ICommodityReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品评价回复管理Service业务层处理
 * 
 * @author fxy
 * @date 2024-08-14
 */
@Service
public class CommodityReplyServiceImpl implements ICommodityReplyService 
{
    @Autowired
    private CommodityReplyMapper commodityReplyMapper;
    @Autowired
    private CommodityLikeEvaluateMapper commodityLikeEvaluateMapper;

    /**
     * 查询商品评价回复管理
     * 
     * @param id 商品评价回复管理主键
     * @return 商品评价回复管理
     */
    @Override
    public CommodityReply selectCommodityReplyById(Long id)
    {
        return commodityReplyMapper.selectCommodityReplyById(id);
    }

    /**
     * 查询商品评价回复管理列表
     * 
     * @param commodityReply 商品评价回复管理
     * @return 商品评价回复管理
     */
    @Override
    public List<CommodityReply> selectCommodityReplyList(CommodityReply commodityReply)
    {
        return commodityReplyMapper.selectCommodityReplyList(commodityReply);
    }

    /**
     * 新增商品评价回复管理
     * 
     * @param commodityReply 商品评价回复管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCommodityReply(CommodityReply commodityReply)
    {
        int result = commodityReplyMapper.insertCommodityReply(commodityReply);
        if (result > 0) {
            // 更新评价的回复量
            return commodityReplyMapper.updateReplyCount(commodityReply.getCommodityEvaluateId());
        }
        return 0;
//        return commodityReplyMapper.insertCommodityReply(commodityReply);
    }

    /**
     * 修改商品评价回复管理
     * 
     * @param commodityReply 商品评价回复管理
     * @return 结果
     */
    @Override
    public int updateCommodityReply(CommodityReply commodityReply)
    {
        return commodityReplyMapper.updateCommodityReply(commodityReply);
    }

    /**
     * 批量删除商品评价回复管理
     * 
     * @param ids 需要删除的商品评价回复管理主键
     * @return 结果
     */
    @Override
    public int deleteCommodityReplyByIds(Long[] ids)
    {
        return commodityReplyMapper.deleteCommodityReplyByIds(ids);
    }

    /**
     * 删除商品评价回复管理信息
     * 
     * @param id 商品评价回复管理主键
     * @return 结果
     */
    @Override
    public int deleteCommodityReplyById(Long id)
    {
        return commodityReplyMapper.deleteCommodityReplyById(id);
    }

    @Override
    public int updateToYes(Long id) {
        return commodityReplyMapper.updateToYes(id);
    }

    @Override
    public int updateToNo(Long id) {
        return commodityReplyMapper.updateToNo(id);
    }
}
